package com.pine.manager.pineframework.convertors;

import com.pine.common.beans.pineframework.request.SysDictItemQueryRequest;
import com.pine.common.beans.pineframework.request.SysDictItemSaveOrUpdateRequest;
import com.pine.common.beans.pineframework.response.SysDictItemQueryResponse;
import com.pine.common.convertor.EntityConvertor;
import com.pine.common.convertor.QueryConvertor;
import com.pine.common.convertor.SaveConvertor;
import com.pine.dao.pineframework.constants.StatusEnum;
import com.pine.dao.pineframework.entity.SysDictItem;
import com.pine.manager.pineframework.bo.SysDictItemBo;
import com.pine.manager.pineframework.query.SysDictItemQuery;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 字典数据表 转换器
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public abstract class SysDictItemConvertor implements EntityConvertor<SysDictItem, SysDictItemBo>,
        QueryConvertor<SysDictItemBo, SysDictItemQuery, SysDictItemQueryRequest, SysDictItemQueryResponse>,
        SaveConvertor<SysDictItemBo, SysDictItemSaveOrUpdateRequest> {

    @Override
    public abstract SysDictItem entityBoToEntity(SysDictItemBo sysDictItemBo);

    @Override
    public abstract SysDictItemBo entityToEntityBo(SysDictItem sysDictItem);

    @Override
    public abstract SysDictItemQueryResponse entityBoToQueryResponse(SysDictItemBo sysDictItemBo);

    @Override
    public abstract SysDictItemQuery queryRequestToQuery(SysDictItemQueryRequest queryRequest);

    @Override
    public abstract List<SysDictItem> entityBoToEntity(List<SysDictItemBo> entityBo);

    @Override
    public abstract List<SysDictItemBo> entityToEntityBo(List<SysDictItem> entity);


    @AfterMapping
    public void afterMappingEntityBoToEntity(@MappingTarget SysDictItem sysDictItem, SysDictItemBo sysDictItemBo) {
        // entityBoToEntity() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToEntity()
    }

    @AfterMapping
    public void afterMappingEntityToEntityBo(@MappingTarget SysDictItemBo sysDictItemBo, SysDictItem sysDictItem) {
        // entityToEntityBo() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityToEntityBo()
    }

    @AfterMapping
    public void afterMappingQueryRequestToQuery(@MappingTarget SysDictItemQuery sysDictItemQuery, SysDictItemQueryRequest sysDictItemQueryRequest) {
        // queryRequestToQuery() 内部其它代码执行完之后，最后会自动执行 afterMappingQueryRequestToQuery()
    }

    @AfterMapping
    public void afterMappingEntityBoToQueryResponse(@MappingTarget SysDictItemQueryResponse sysDictItemQueryResponse, SysDictItemBo sysDictItemBo) {
        // entityBoToQueryResponse() 内部其它代码执行完之后，最后会自动执行 afterMappingEntityBoToQueryResponse()
    }

    public StatusEnum integerToStatusEnum(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        return StatusEnum.of(code);
    }

    public Integer statusEnumToInteger(StatusEnum statusEnum) {
        if (Objects.isNull(statusEnum)) {
            return null;
        }
        return statusEnum.getCode();
    }
}
